package com.hpin.fansea.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import android.widget.Toast;

import com.hpin.fansea.R;
import com.hpin.fansea.bean.RepairDetail;

import java.util.List;

/**
 * Created by Aaron on 15/9/23.
 */
public class PayRecordAdapter extends BaseAdapter {

    private List<RepairDetail> repairDetailList;
    private Context context;

    public PayRecordAdapter(Context context, List<RepairDetail> repairDetailList) {
        this.repairDetailList = repairDetailList;
        this.context = context;
    }

    public void setRepairDetailList(List<RepairDetail> repairDetailList) {
        this.repairDetailList = repairDetailList;
    }

    @Override
    public int getCount() {
        return repairDetailList.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHoleder holeder = null;

        if (convertView == null) {
            convertView = View.inflate(context, R.layout.item_pay_record, null);
            holeder = new ViewHoleder();
            holeder.pay_name = (TextView) convertView.findViewById(R.id.pay_name);
            holeder.pay_price = (TextView) convertView.findViewById(R.id.pay_price);

            convertView.setTag(holeder);
        }else {
            holeder = (ViewHoleder) convertView.getTag();
        }

        try {

            //设置支付时间
//            if (!TextUtils.isEmpty(repairDetailList.get(position).payTime)) {
//                holeder.pay_price.setText(AbDateUtil.getStringByFormat(repairDetailList.get(position).year, "yyyy") + "年物业费");
                holeder.pay_price.setText(repairDetailList.get(position).year + "年物业费");
//            }

//            //设置支付的总金额
//            double caush = 0;//现金
//            double redPacket = 0;//红包
//            String caushMoney = repairDetailList.get(position).money;
//            if (!TextUtils.isEmpty(caushMoney)) {
//                caush = Double.parseDouble(caushMoney);
//            }
//            String redPacketMoney = repairDetailList.get(position).redPacket;
//            if (!TextUtils.isEmpty(redPacketMoney)) {
//                redPacket = Double.parseDouble(redPacketMoney);
//            }
            holeder.pay_name.setText(repairDetailList.get(position).ordCash + "元");

        } catch (Exception e) {
            e.printStackTrace();
            Toast.makeText(context, "数据异常", Toast.LENGTH_SHORT).show();
            holeder.pay_name.setText("0元");
        }

        return convertView;
    }


    class ViewHoleder {
        private TextView pay_name, pay_price;
    }

}
